﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using SailHero.Soft.FrameWork.Models;

namespace UI.Web.MVC.Common
{
    [HandleError]
    public class BaseController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpContextBase ctx = filterContext.HttpContext;
            //if (ctx.Session != null)
            //{
            //    if (ctx.Session.IsNewSession)
            //    {
            //        string sessionCookie = ctx.Request.Headers["Cookie"];
            //        if ((null != sessionCookie) && (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
            //        {
            //            ctx.Response.Redirect("~/Search/Index");
            //        }
            //    }
            //}
            if (Session["user"] == null)
            {
                ctx.Response.Redirect("~/Account/LogOn");
            }
            base.OnActionExecuting(filterContext);
        } 

        public Sys_User LoginUser
        {
            get 
            {
                if (Session["user"] == null)
                {
                    FormsAuthentication.SignOut();
                }
                return Session["user"] as Sys_User;
            }
        }
    }
}